import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/buttons/myFavoriteButtonBar.dart';
import 'package:ichinesereader/widgets/grids/bookGridWithCheckBox.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/widgets/grids/bookGridSimplified.dart';

class MyFavoriteBooksForStudent extends GetView<BooksController> {

  @override
  Widget build(BuildContext context) {
    Log.debug('build student MyFavorites');
    final box = Hive.box('appconfig');
    bool isStudent = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Student;
    bool isParent = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Parent;

    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Column(
        children: [
          Container(
            height: 60.0,
            child: (isStudent || isParent) ? FavoriteButtonBar() : Text(''),
          ),
          isParent ?
          Expanded(
              child: controller.obx(
            (data) => BookGridSimplified(
              books: controller.myFavoriteBookItems
            ),
            onEmpty: Center(child: Text('No book has been added'.tr)),
          )):
          Expanded(
              child: controller.obx(
            (data) => BookGridWithCheckBox(
              books: controller.myFavoriteBookItems,
              readingType: NanhaiBookReadingTypes.favorite,
            ),
            onEmpty: Center(child: Text('No book has been added'.tr)),
            onLoading: Container(),
          )),
        ],
      ),
    );
  }
}
